package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingPlanPageDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanProjectVo;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划相关接口")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult findAll() {
        List<NursingPlanVo> nursingPlanVo = nursingPlanService.findAll();
        return success(nursingPlanVo);
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult insert(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.insert(nursingPlanDto);
        return success();
    }

    @GetMapping("/search")
    @ApiOperation("分页查询所有护理计划")
    public ResponseResult findPage(NursingPlanPageDto nursingPlanPageDto) {
        PageResponse nursingPlanVo = nursingPlanService.findPage(nursingPlanPageDto);
        return success(nursingPlanVo);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult findById(@PathVariable Long id) {
        NursingPlanProjectVo nursingPlan = nursingPlanService.findById(id);
        return success(nursingPlan);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult update(@PathVariable Long id, @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.update(nursingPlanDto);
        return success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult deleteById(@PathVariable Long id) {
        nursingPlanService.deleteById(id);
        return success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingPlanService.updateStatus(id, status);
        return success();
    }

}
